package com.leaf.collegeidleapp;

import android.app.Application;
import android.content.Intent;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.recyclerview.widget.RecyclerView;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import com.leaf.collegeidleapp.bean.Collection;
import com.leaf.collegeidleapp.bean.Commodity;
import com.leaf.collegeidleapp.bean.Star;
import com.leaf.collegeidleapp.util.CommodityDbHelper;
import com.leaf.collegeidleapp.util.MyCollectionDbHelper;
import com.leaf.collegeidleapp.util.StarDBHelper;

import java.util.ArrayList;
import java.util.List;

public class TalkActivity extends AppCompatActivity {

    private EditText inputText;
    private Button send;
    private RecyclerView msgRec;
    private TextView outputText;
    private TextView outputText2;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_talk);

        send = findViewById(R.id.bt_send);
        inputText = findViewById(R.id.et_input);
        outputText = findViewById(R.id.tv_talk);
        outputText2 = findViewById(R.id.tv_talk2);

        send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String text = inputText.getText().toString();
                outputText.setText(text);
                outputText2.setText("(Robot)：Sorry, Sold out already!");
                inputText.setText("");

            }
        });

        //关注按钮
        ImageButton ibStar = findViewById(R.id.ib_star);
        ibStar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                StarDBHelper dbHelper = new StarDBHelper(getApplicationContext(),StarDBHelper.DB_NAME,null,1);
                Star star = new Star();
                String stuId = getIntent().getStringExtra("stuId");
                star.setStuId(stuId);

                CommodityDbHelper dbHelper1 = new CommodityDbHelper(getApplicationContext(),CommodityDbHelper.DB_NAME,null,1);
                List<Commodity> myCommodities = new ArrayList<>();
                myCommodities = dbHelper1.readMyCommoditiesPhone(stuId);
                star.setPhone(myCommodities.get(0).getPhone());
                dbHelper.addMyStar(star);
                Toast.makeText(getApplicationContext(),"成功关注了用户"+stuId,Toast.LENGTH_SHORT).show();
            }
        });

    }
}